<?php
/**
 * Created by PhpStorm.
 * User: xeng
 * Date: 2018/1/20
 * Time: 17:14
 * 游戏卡  类
 */
namespace Home\Controller;
use Think\Controller;
use Think\Exception;

class GamecardController extends AuthController
{
    public function index()
    {
        //拿到条件 分页查询
        $condi=$_GET;
        $condi=array_merge($condi,$_POST);
        $p=$condi['p']?$condi['p']:1;         //第几页
        $listRows=40;                      //每页记录数
        $firstRow =($p-1)*$listRows;
        $count =$this->game("SELECT card_group from web_gamecard group by card_group");
        $count=count($count);
        $lista=$this->game("SELECT   card_owner,card_group,acard_type,card_create_time,
                            card_gold,count(*) as total,sum(card_gold) as total_gold,SUM(CASE WHEN user_game_id > 0 THEN 1 ELSE 0 END) as czpeo,
                            SUM(CASE WHEN user_game_id is null THEN 1 ELSE 0 END) as nczpeo
                            from web_gamecard  group by card_owner,card_group,acard_type,card_gold,card_create_time 
                            order by card_create_time desc limit $firstRow,$listRows");
        foreach ($lista as $key => $value) {
            $card_group=$value['card_group'];
            $re=$this->game("SELECT card_type FROM web_gamecard where  card_group='$card_group' and card_type=-2");
            if($re){
                $lista[$key]['card_type']=-2;
            }else{
                $lista[$key]['card_type']=1;
            }
            if($value["acard_type"]== (int)0){
                $lista[$key]["card_type_name"]= " <i class='fa fa-thumbs-up' style='color: #30be00;'></i> 新手卡";
            }elseif ($value["acard_type"]==(int)1){
                $lista[$key]["card_type_name"]= "<i class='fa fa-buysellads' style='color: #f55200;'></i> 充值卡";
            }
            $lista[$key]["card_gold"]= $value['card_gold']/1000;
            $lista[$key]["total_gold"]= $value['total_gold']/1000;
        }
        $show = $this->page_show($count,$listRows,$p);
        $shows=$show;
        $pg=array_pop($shows);
        $r=$this->actionLog('全部','查询了','游戏卡');
        $this->assign("totalPages",$pg);
        $this->assign('condi',$condi); //保留查询条件
        $this->assign('count',$count);
        $this->assign("lists",$lista);// 分页后 数组
        // $this->assign("page_show",$show); //分页按钮组
        $this->assign('p', $p);
        $this->display();
    }

    public function getcard()
    {
        $this->CheckPower('2001');
        $this->assign('selects', $this->selects());
        $this->display('groups');
    }
//[{"id":1001,"num":2},{"id":1002,"num":2},{"id":1003,"num":1}]
    //增加银币
    public function add(){
        if(IS_POST){
            $commands = M('','','DB_CONFIG1');
            $gameid = I('post.gameid');
            if(I('post.1001') >= 0 && I('post.1002') >=0 && I('post.1003')>=0){

            }else{
                $data['code'] = 0;
                $data['msg'] = '操作失误，不能提交负数';
                $this->ajaxReturn($data);
            }
            $serverID = C('DATA_HOST');
            $rpcname="addsilver";
            $time=date("Y-m-d H:i:s",time());
            $i=0;
            if(I('post.1001')>0){
                $add[$i]['ServerIPAddr'] =$serverID;
                $command=array(
                    'gameid'=>intval($gameid),
                    'id'=>1001,
                    'num'=>intval(I('post.1001'))
                );
                $command = json_encode($command);
                $add[$i]['ServerIPAddr'] =$serverID;
                $add[$i]['Command'] =$command;
                $add[$i]['RpcName'] =$rpcname;
                $add[$i]['Time'] =$time;
                $i++;
            }

            if(I('post.1002')>0){
                $add[$i]['ServerIPAddr'] =$serverID;
                $command2=array(
                    'gameid'=>intval($gameid),
                    'id'=>1002,
                    'num'=>intval(I('post.1002'))
                );
                $command2 = json_encode($command2);
                $add[$i]['ServerIPAddr'] =$serverID;
                $add[$i]['Command'] =$command2;
                $add[$i]['RpcName'] =$rpcname;
                $add[$i]['Time'] =$time;
                $i++;
            }

            if(I('post.1003')>0){
                $add[$i]['ServerIPAddr'] =$serverID;
                $command3=array(
                    'gameid'=>intval($gameid),
                    'id'=>1003,
                    'num'=>intval(I('post.1003'))
                );
                $command3 = json_encode($command3);
                $add[$i]['ServerIPAddr'] =$serverID;
                $add[$i]['Command'] =$command2;
                $add[$i]['RpcName'] =$rpcname;
                $add[$i]['Time'] =$time;
            }


            $re = $commands->table('data_command')->addAll($add);
            $data['code'] = 0;
            $data['msg'] = '操作失误，提交失败';
            if($re){
                $data['code'] = 1;
                $data['msg'] = '操作成功';
            }
            $this->ajaxReturn($data);
        }
        $this->assign('id',$_GET['id']);
        $this->assign('gold50',$_GET['gold50']);
        $this->assign('gold100',$_GET['gold100']);
        $this->assign('gold200',$_GET['gold200']);
        $this->display('add');
    }

    //减去银币
    public function deleteyinbi(){
        if(IS_POST){
            $commands = M('','','DB_CONFIG1');
            $gameid = I('post.gameid');
            if(I('post.1001') >= 0 && I('post.1002') >=0 && I('post.1003')>=0){

            }else{
                $data['code'] = 0;
                $data['msg'] = '操作失误，不能提交负数';
                $this->ajaxReturn($data);
            }
            $serverID = C('DATA_HOST');
            $rpcname="resilver";
            $time=date("Y-m-d H:i:s",time());
            $i=0;
            if(I('post.1001')>0){
                $add[$i]['ServerIPAddr'] =$serverID;
                $command=array(
                    'gameid'=>intval($gameid),
                    'id'=>1001,
                    'num'=>intval(I('post.1001'))
                );
                $command = json_encode($command);
                $add[$i]['ServerIPAddr'] =$serverID;
                $add[$i]['Command'] =$command;
                $add[$i]['RpcName'] =$rpcname;
                $add[$i]['Time'] =$time;
                $i++;
            }

            if(I('post.1002')>0){
                $add[$i]['ServerIPAddr'] =$serverID;
                $command2=array(
                    'gameid'=>intval($gameid),
                    'id'=>1002,
                    'num'=>intval(I('post.1002'))
                );
                $command2 = json_encode($command2);
                $add[$i]['ServerIPAddr'] =$serverID;
                $add[$i]['Command'] =$command2;
                $add[$i]['RpcName'] =$rpcname;
                $add[$i]['Time'] =$time;
                $i++;
            }

            if(I('post.1003')>0){
                $add[$i]['ServerIPAddr'] =$serverID;
                $command3=array(
                    'gameid'=>intval($gameid),
                    'id'=>1003,
                    'num'=>intval(I('post.1003'))
                );
                $command3 = json_encode($command3);
                $add[$i]['ServerIPAddr'] =$serverID;
                $add[$i]['Command'] =$command3;
                $add[$i]['RpcName'] =$rpcname;
                $add[$i]['Time'] =$time;
            }
            $re = $commands->table('data_command')->addAll($add);
            $data['code'] = 0;
            $data['msg'] = '操作失误，提交失败';
            if($re){
                $data['code'] = 1;
                $data['msg'] = '操作成功';
            }
            $this->ajaxReturn($data);
        }
        $this->assign('id',$_GET['id']);
        $this->assign('id',$_GET['id']);
        $this->assign('gold50',$_GET['gold50']);
        $this->assign('gold100',$_GET['gold100']);
        $this->assign('gold200',$_GET['gold200']);
        $this->display('delete');
    }

    public function get_gamecard(){
        S(array('type'=>'file','prefix'=>'goods','expire'=>60*60));
        $useraccount = M('','','DB_CONFIG1');
        $url = pageurl(__SELF__);
        $pagesize = empty($url['limit'])?90:$url['limit'];
        $page = empty($url['page'])?1:$url['page'];
        $state = ($page-1)*$pagesize;
        //$where['_string']="goods <> ''";
        if($url['gameid'] > 0 && !empty($url['gameid'])){
            $where['gameid'] = array('eq',$url['gameid']);
        }

        if(!empty($url['status'])){

            switch ($url['status']){
                case '0':

                    $this-> actionLog('离线玩家','查询了所有','信息');
                    $where['_string'] = 'ongameid IS null'; //离线
                    break;
                case '1':

                    $where['usertype'] = array('eq','3');//代理
                    break;
                case '2':
                    //$where['usertype'] = array('like','%'.$url['status'].'%');

                    $this-> actionLog('在线玩家','查询了所有','信息');
                    $where['_string'] = 'ongameid IS NOT null';//在线
                    break;
                case '3':
                      //删除默认值离线查询全部
                    $this-> actionLog('玩家','查询了所有','信息');
                    break;
                case '4':
                    // $where['usertype'] = array('like','%'.$url['status'].'%');
                    $where['disablelogin'] = array('eq',1);//冻结玩家
                    break;
                default:
                    break;
            }
        }
       // $list = S('gmae_goods'.$page.$pagesize);
       // $count = S('gmae_goods');
        $count =$useraccount->table('data_useraccount')->where($where)->count();
        $list = $useraccount->table('data_useraccount')->field('gameid,nickname,goods')->where($where)->limit($state,$pagesize)->select();
        $s = $useraccount->table('data_useraccount')->fetchSql(true)->field('gameid,nickname,goods')->where($where)->limit($state,$pagesize)->select();
       /* if($count < 0 || $count !=$count2 || empty($list) || !empty($url['gameid'])){

            S('gmae_goods'.$page.$pagesize,$list);
            $count = $count2;
            S('gmae_goods',$count);
        }*/
        foreach ($list as $key => $value) {
            $gold = json_decode($value['goods'],true);
            $list[$key]["gold50"]  = 0;
            $list[$key]["gold100"]  =0;
            $list[$key]["gold200"]  =0;
            foreach ($gold as $v){
                switch ($v['id']){
                    case 1001:
                        $list[$key]["gold50"]  = $v['num'];//50 银币
                        break;
                    case 1002:
                        $list[$key]["gold100"] = $v['num'];//100 银币
                        break;
                    case 1003:
                        $list[$key]["gold200"] = $v['num'];//200 银币
                        break;
                }
            }

            $list[$key]["sumgold"] = intval($list[$key]["gold50"])*50+intval($list[$key]["gold100"])*100*intval($list[$key]["gold200"])*200;

            $list[$key]["usegold"] = $this->getnum($value['gameid']); //本周使用银币总额
        }
       // $d[0]['gameid'] = 123456;
       // $d[0]['nickname'] = '张三';
       // $d[0]['ServerName'] = 50;
        $data['code'] = 0;
        $data['message'] =$gold;
        $data['count'] = $count;
        $data['data'] = $list;
        $this->ajaxReturn($data,'json');
    }

    public function getnum($gameid){
        $coinuse = M('','','DB_CONFIG2');
        $str = 0;
       $list = $coinuse->table('log_coinuse')->field('gameid,SUM(count) as num,coinid')->where("time >= DATE_FORMAT(DATE_SUB(now(),INTERVAL WEEKDAY(now()) day),'%Y-%m-%d 00:00:00') and gameid=$gameid")->group("gameid,coinid")->select();
       if(!empty($list)){
           foreach ($list as $v){
               switch ($v['coinid']){
                   case 1001:
                       $str =$str+$v['num']*50;
                       break;
                   case 1002:
                       $str =$str+$v['num']*100;
                       break;
                   case 1003:
                       $str =$str+$v['num']*200;
                       break;
               }
           }
       }

       return $str;
    }

    public function getgameinfo(){
        S(array('type'=>'file','prefix'=>'gamecard','expire'=>60*60));
        $useraccount = M('','','DB_CONFIG1');
        $url = pageurl(__SELF__);
        $pagesize = empty($url['limit'])?10:$url['limit'];
        $page = empty($url['page'])?1:$url['page'];
        $state = ($page-1)*$pagesize;
        //$where['_string']="goods <> ''";
        if(!empty($url['card_group'])){
            $where['card_group'] = array('eq',$url['card_group']);
        }
        $list = S('getgameinfo'.$url['card_group']);
        $count = count($list);
        if(empty($list)){
            $count =$useraccount->table('web_gamecard')->where($where)->count();
            $list = $useraccount->table('web_gamecard')->where($where)->limit($state,$pagesize)->order('user_use_time desc')->select();
            foreach ($list as $k=>$v){
                $list[$k]['card_gold'] =round($v['card_gold']/1000,2);
            }
            S('getgameinfo'.$url['card_group'],$list);
        }

        $data['code'] = 0;
        $data['message'] ='';
        $data['count'] = $count;
        $data['data'] = $list;
        $this->ajaxReturn($data,'json');
    }

    public function getgoldname($id){
        $str[] = ['id'=>1001,'key_name'=>'gold50','name'=>'50银币卡'];
        $str[] = ['id'=>1002,'key_name'=>'gold100','name'=>'100银币卡'];
        $str[] = ['id'=>1003,'key_name'=>'gold200','name'=>'100银币卡'];
        $msg="";
        foreach($str as $key=> $n){
            if($n['id'] == $id){
                return $str[$key];
            }
        }
        return substr($msg,0,-1);
    }

    //金币操作
    public function gold(){
        if(!empty($_GET['gameid']) && isset($_GET['gameid'])){
            if(IS_GET){
                $id=$_GET['gameid'];
                $useraccount = M('','','DB_CONFIG1');
                $count2 =$useraccount->table('data_useraccount')->field('gameid,nickname,disablelogin,account')->where('gameid='.$id)->find();
                $data['code'] = 0;
                $data['msg'] = '查询失败';
                if (!empty($count2)) {
                    $data['code'] = 1;
                    $data['msg'] = '查询成功';
                    $num =$useraccount->table('data_userscore')->field('score')->where('gameid='.$id)->find();
                    $data['gold'] = $num['score'];
                    $data['list'] = $count2;
                }
                $this->ajaxReturn($data);
            }
        }

     /*   $redis = new \Redis();
        $redis->connect('192.168.1.102',6379);
       // $redis->set('myname','ztm');
       // echo $redis->get('myname');
        //echo $redis->ping();=
        $gameid = 1022376-1000100;
        $d = $redis->hGet($gameid, 'score');
        var_dump($d);

        print_r($d);*/
        $this->display('gold');
    }

    /*
     * 根据 游戏卡号查一条  顶部查询
     * get one by card_no
     */
    public function getOneByCard_no(){
        $this->CheckPower('2002');
        $card_no = $_GET['card_no']; //dump($card_no);
        $card_no = "'".trim($card_no)."'" ; //dump($card_no);
        $card=trim($_GET['card_no']);
        if(trim($_GET['card_no'])){
            $r=$this->actionLog($card,'查询了单张为','游戏卡');
            $data = $this->game("
              SELECT * FROM web_gamecard WHERE card_no = $card_no;
            ");   
            $data = $this->fieldNeedZH(reset($data));  
            $this->assign('data',$data);
        }
        $this->display('games');
    }

    /*
     * 批量创建 游戏卡
     * create
     */
    public function create()
    {
        $this->CheckPower('2003');
        // G('begin');
        if (IS_POST) {
            $con = $_POST;// var_dump($con);die;
            if (!empty($con['count']) &&
                $con['card_type'] !== null &&
                !empty($con['card_gold']) &&
                !empty($con['card_owner']) &&
                !empty($con['card_no_prefix'])
            ) {
                //验证循环次数
                //2018-12-2 修改优化增加大量数据（2万条）等待时间
                if (intval($con['count'])) {
                    $this->alert('几秒后生成，完成后刷新查看','请赖心等待...',1000); //防止重复提交
                    $card_group = $con['card_no_prefix'] ? trim($con['card_no_prefix']) . rand(100, 999) . time() : "default" . rand(100, 999) . time();
                    if ($con['card_type'] == 1) {
                        $ss = '充值卡';
                    } else {
                        $ss = '新手卡';
                    }
                    $r = $this->actionLog($card_group, '添加了卡组为', $ss);
                    $card_group = "'" . $card_group . "'";
                    $card_create_time = "'" . date("Y-m-d  H:i:s") . "'";

                    $chu = (int)($con['count'] / 5000);
                    $yu = $con['count'] % 5000;
                    ini_set('max_execution_time', '0');
                    if ($chu > 0) {
                        for ($i = 0; $i < $chu; $i++) {
                            $values = '';
                            for ($j = $i * 5000; $j < ($i + 1) * 5000; $j++) {
                                $astrlen = 19;
                                $strlen = strlen(trim($con['card_no_prefix']));
                                $sj = $this->GetRandStr((int)$astrlen - (int)$strlen);//为随机字符串个数

                                $card_no = "'" . trim($con['card_no_prefix']) . $sj . "'";
                                $card_owner = "'" . trim($con['card_owner']) . "'";
                                $card_type = $con['card_type'];
                                $card_create_time = $card_create_time;
                                $card_gold = trim($con['card_gold']) * 1000;
                                $user_game_id = "";
                                $user_nike_name = "";
                                $user_use_time = "";
                                $card_group = strtolower($card_group);

                                //11-29 修改该字段成小写
                                $card_no = strtolower($card_no);
                                substr(strtolower($card_no), 0, 18);
                                $values .= "($card_no,$card_owner,$card_type,$card_create_time,$card_gold,$card_group,$card_type),";
                            }
                            $values = substr($values, 0, -1);
                            $reset = $this->game("INSERT  INTO web_gamecard (card_no,card_owner,acard_type,card_create_time,card_gold,card_group,card_type) VALUES " . $values);
                        }
                        $ddd="";
                        for ($i = 0; $i < $yu; $i++) {
                            $astrlen = 19;
                            $strlen = strlen(trim($con['card_no_prefix']));
                            $sj = $this->GetRandStr((int)$astrlen - (int)$strlen);//为随机字符串个数

                            $card_no = "'" . trim($con['card_no_prefix']) . $sj . "'";
                            $card_owner = "'" . trim($con['card_owner']) . "'";
                            $card_type = $con['card_type'];
                            $card_create_time = $card_create_time;
                            $card_gold = trim($con['card_gold']) * 1000;
                            $user_game_id = "";
                            $user_nike_name = "";
                            $user_use_time = "";
                            $card_group = strtolower($card_group);

                            //11-29 修改该字段成小写
                            $card_no = strtolower($card_no);
                            substr(strtolower($card_no), 0, 18);
                            $ddd .= "($card_no,$card_owner,$card_type,$card_create_time,$card_gold,$card_group,$card_type),";
                        }
                       // $this->alert('几秒后生成，完成后刷新查看','请赖心等待...',1000);
                        $ddd=substr($ddd, 0, -1);
                        $reset = $this->game("INSERT  INTO web_gamecard (card_no,card_owner,acard_type,card_create_time,card_gold,card_group,card_type) VALUES " . $ddd);
                    }else{
                        $values = '';
                        for ($j = 0; $j < intval($con['count']); $j++) {
                            $astrlen = 15;
                            $strlen = strlen(trim($con['card_no_prefix']));
                            $sj = $this->GetRandStr((int)$astrlen - (int)$strlen);//为随机字符串个数

                            $card_no = "'" . trim($con['card_no_prefix']) . $sj . "'";
                            $card_owner = "'" . trim($con['card_owner']) . "'";
                            $card_type = $con['card_type'];
                            $card_create_time = $card_create_time;
                            $card_gold = trim($con['card_gold']) * 1000;
                            $user_game_id = "";
                            $user_nike_name = "";
                            $user_use_time = "";
                            $card_group = strtolower($card_group);

                            //11-29 修改该字段成小写
                            $card_no = strtolower($card_no);
                            substr(strtolower($card_no), 0, 18);
                            $values .= "($card_no,$card_owner,$card_type,$card_create_time,$card_gold,$card_group,$card_type),";
                        }
                        $values = substr($values, 0, -1);
                        $reset = $this->game("INSERT  INTO web_gamecard (card_no,card_owner,acard_type,card_create_time,card_gold,card_group,card_type) VALUES " . $values);
                    }

                     die;
                }else{
                    $this->error("<h1 class='text-danger'>参数不能为空</h1>",'index',2);
                }
            }
            die;
        }
        //展示页面
        $this->display('create');
    }
    ///随机取
    function GetRandStr($len) {  
        $chars = array(  
            'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','0','1','2','3','4','5','6','7','8','9');  
        $charsLen = count($chars) - 1;  
        shuffle($chars);  
        $output = '';  
        for ($i = 0; $i < $len; $i++) {  
            $output .= $chars[mt_rand(0, $charsLen)];  
        }  
        return $output;  
    }  
  



    /*
     * 查看一批 详情
     * detail
     */
    public function detail(){
        //拿到条件 分页查询
        $this->CheckPower('2001');
        if(!$_GET['card_group'] || $_GET['card_group']=='undefined'){
            $this->err404();
        }

        $con =$_GET['card_group']; //查询条件保留
        $this->assign('con',$con);
        $this->display("gameinfo");
    }


    /*
     * 导出一批
     * exl 创建(导出)Excel数据表格
     */
    public function  exlgroup(){
        $card_group = $_GET['card_group'];
        $card_group_where = "'".$card_group."'";
        if($card_group){
            $lists= $this->game("
            SELECT id,card_no,card_owner,card_type,card_create_time,card_gold  FROM web_gamecard WHERE  card_group=$card_group_where
            ");
            //导出
            $filename = '，第-'.$card_group.'-批次'.date('YmdHis');
            $header = array('ID','游戏卡号','销售商','类型','创建时间','金额');
            $index = array('id','card_no','card_owner','card_type','card_create_time','card_gold');
            $this->createtable($lists,$filename,$header,$index);
        }
    }


    /*
     * 冻结
     * del card_group
     * bool
     */
    public function dgroup(){
        $con = $_GET['card_group'];
        if($con){
            $useraccount = M('','','DB_CONFIG1');
            $d['card_type'] = -2;
            $count2 =$useraccount->table('web_gamecard')->where("card_type in (0,1) and card_group='".$con."'")->save($d);
           // $s =$useraccount->table('web_gamecard')->fetchSql(true)->where("card_type=-2 and card_group='".$con."'")->save($d);
            if($count2){
                 $result['code']='success';
            }else{
                 $result['code']='fail';
            }
        }
        $this->ajaxReturn($result);   
    }
    /*
        解冻
    */
    public function nodgroup(){

        $id=$_GET['card_group'];
        $useraccount = M('','','DB_CONFIG1');
        $d['card_type'] = 1;
        $count2 =$useraccount->table('web_gamecard')->where("card_type=-2 and card_group='".$id."'")->save($d);
       /* $con = $_GET['card_group'];  ///-2冻结  -1使用 1充值卡  0新手卡
        $acard=$this->game("SELECT id,card_type,user_game_id,acard_type from web_gamecard where card_group='$con' and card_type=-2");
        foreach ($acard as $key => $value) {
            $id=$value['id'];
            if($value['user_game_id']){
                $reset= $this->game("UPDATE web_gamecard SET  card_type=-1     WHERE id = $id"); 
            }else{
                if($value['acard_type']==1){  //充值卡
                    $reset= $this->game("UPDATE web_gamecard SET  card_type=1     WHERE id = $id");     
                }else{
                    $reset= $this->game("UPDATE web_gamecard SET  card_type=0     WHERE id = $id"); 
                }
            }
        }*/
        if($count2){
             $result['code']='success';
            // $this->alert('解冻成功，请稍等','OK',3000);
        }else{
            // $this->alert('解冻失败！',';(',3000);
             $result['code']='fail';
        } 
        $this->ajaxReturn($result); 

    } 
    /*
     冻结单张卡
    */   
     public function onedgroup(){
        $id=$_GET['id'];
        $reset= $this->game("UPDATE web_gamecard SET  card_type=-2     WHERE id = $id and card_type=0");
        if($reset){
             $result['code']='success';
        }else{
             $result['code']='fail';
        } 
        $this->ajaxReturn($result); 
     }
     /*
        解冻单张卡
     */
    public function onenodgroup(){
        $id=$_GET['id'];
        $acard=$this->game("SELECT id,card_type,user_game_id,acard_type from web_gamecard where id=$id");
        foreach ($acard as $key => $value) {
            $id=$value['id'];
            if($value['user_game_id']){
                $reset= $this->game("UPDATE web_gamecard SET  card_type=-1     WHERE id = $id"); 
            }else{
                if($value['acard_type']==1){  //充值卡
                    $reset= $this->game("UPDATE web_gamecard SET  card_type=1     WHERE id = $id");     
                }else{
                    $reset= $this->game("UPDATE web_gamecard SET  card_type=0     WHERE id = $id"); 
                }
            }
        }
        if($reset){
             $result['code']='success';
        }else{
             $result['code']='fail';
        } 
        $this->ajaxReturn($result); 
    }    
    /*
     * 删除一条
     * del id
     */
    public function dOne(){
        $con = $_GET['id'];
        if($con){
            $reset= $this->game("DELETE FROM web_gamecard  WHERE id = '$con'"); 
            if($reset){
                $this->alert('删除成功，请稍等','OK',3000);
                die;
            }
            $this->alert('删除失败！',';(',3000);die;
        }
        $this->alert('删除条件错误！',';(',5000);
    }




    /*
 * 字段名称 变成中文
 * web_gamecard  游戏卡表
 * return array
 */
    protected function fieldZH($arr){
        //判断是lists 、data
        $arrOne = reset($arr);

        if(!is_array($arrOne)){ //$data 1维数组
            $reset =  $this->fieldNeedZH($arr);
            return $reset;
        }
        if(is_array($arrOne)){ //$lists 2维数组
            foreach ($arr as $v){
                $reset[] =  $this->fieldNeedZH($v);
            }
            return $reset;
        }

    }
    /*
     * 汉化 所有字段
     *  web_gamecard  游戏卡表
     *  $arr 一维数组
     *  return array
     */
    protected function fieldAllZH22($arr){
        $reset['accountid']['value']=$arr['accountid'];
        $reset['accountid']['ZH']="会员ID";

        $reset['account']['value']=$arr['account'];
        $reset['account']['ZH']="注册名称";

        $reset['gameid']['value']=$arr['gameid'];
        $reset['gameid']['ZH']="游戏ID";

        $reset['nikename']['value']=$arr['nikename'];
        $reset['nikename']['ZH']="用户名";

        $reset['faceid']['value']=$arr['faceid'];
        $reset['faceid']['ZH']="头像ID";

        $reset['experience']['value']=$arr['experience'];
        $reset['experience']['ZH']="经验值";

        $reset['sex']['value']=$arr['sex'];
        $reset['sex']['ZH']="性别";

        $reset['moormachine']['value']=$arr['moormachine'];
        $reset['moormachine']['ZH']="绑定机器";

        $reset['usertype']['value']=$arr['usertype'];
        $reset['usertype']['ZH']="用户类型";

        $reset['devicetype']['value']=$arr['devicetype'];
        $reset['devicetype']['ZH']="设备类型";

        $reset['spreaderaccount']['value']=$arr['spreaderaccount'];
        $reset['spreaderaccount']['ZH']="推荐人账号";

        $reset['phonenum']['value']=$arr['phonenum'];
        $reset['phonenum']['ZH']="绑定手机";

        $reset['disablelogin']['value']=$arr['disablelogin'];
        $reset['disablelogin']['ZH']="禁止登陆";

        $reset['crontolstatus']['value']=$arr['crontolstatus'];
        $reset['crontolstatus']['ZH']="操作状态";

        $reset['use_novice_card']['value']=$arr['use_novice_card'];
        $reset['use_novice_card']['ZH']="新手卡";

        $reset['winwealth']['value']=$arr['winwealth'];
        $reset['winwealth']['ZH']="取胜";

        $reset['bankgold']['value']=$arr['bankgold'];
        $reset['bankgold']['ZH']="库金";

        $reset['row_number']['value']=$arr['row_number'];
        $reset['row_number']['ZH']="行号";

        $reset['country']['value']=$arr['country'];
        $reset['country']['ZH']="国家";

        $reset['province']['value']=$arr['province'];
        $reset['province']['ZH']="省份";

        $reset['city']['value']=$arr['city'];
        $reset['city']['ZH']="城市";

        $reset['openid']['value']=$arr['openid'];
        $reset['openid']['ZH']="微信openid";

        $reset['unionid']['value']=$arr['unionid'];
        $reset['unionid']['ZH']="微信unionid";

        $reset['refresh_token']['value']=$arr['refresh_token'];
        $reset['refresh_token']['ZH']="微信refresh_token";

        $reset['headimgurl']['value']=$arr['headimgurl'];
        $reset['headimgurl']['ZH']="头像地址";

        $reset['pwd']['value']=$arr['pwd'];
        $reset['pwd']['ZH']="登录密码";

        $reset['bankpwd']['value']=$arr['bankpwd'];
        $reset['bankpwd']['ZH']="库金密码";

        return $reset;
    }
    /*
    * 汉化 需要的 字段
    *  web_gamecard  游戏卡表
    *  $arr 一维数组
    *  return array
    */
    protected function fieldNeedZH($arr){
        if(array_key_exists("id", $arr)){
            $reset['id']['value']=$arr['id'];
            $reset['id']['ZH']="ID";
        }
        if(array_key_exists("card_no", $arr)){
            $reset['card_no']['value']=$arr['card_no'];
            $reset['card_no']['ZH']="游戏卡号";
        }
        // if(array_key_exists("card_owner", $arr)){
        //     $reset['card_owner']['value']=$arr['card_owner'];
        //     $reset['card_owner']['ZH']="所以者";
        // }
        if(array_key_exists("card_type", $arr)){
                if($arr['card_type']== (int)0){
                    $reset['card_type']['value']= " <i class='fa fa-thumbs-up' style='color: #30be00;'></i> 新手卡";
                }elseif ($arr['card_type']==(int)1){
                    $reset['card_type']['value']= "<i class='fa fa-buysellads' style='color: #f55200;'></i> 充值卡";
                }elseif ($arr['card_type']==(int)-1){
                    $reset['card_type']['value']="已使用";   //已使用
                }elseif($arr['card_type']==(int)-2){
                    $reset['card_type']['value']="被冻结";   //被冻结
                } 
            // $reset['card_type']['value']=$arr['card_type'];
            $reset['card_type']['ZH']="使用状态";
        }

       

        if(array_key_exists("acard_type", $arr)){
            if($arr['acard_type']== (int)0){
                    $reset['acard_type']['value']= " <i class='fa fa-thumbs-up' style='color: #30be00;'></i> 新手卡";
            }elseif ($arr['acard_type']==(int)1){
                $reset['acard_type']['value']= "<i class='fa fa-buysellads' style='color: #f55200;'></i> 充值卡";
            }
            $reset['acard_type']['ZH']="卡类型";
        }
        if(array_key_exists("card_gold", $arr)){
            $reset['card_gold']['value']=$arr['card_gold'];
            $reset['card_gold']['ZH']="金额";
        }
        if(array_key_exists("card_state", $arr)){
            $reset['card_state']['value']=$arr['card_state'];
            $reset['card_state']['ZH']="状态";
        }
        if(array_key_exists("user_game_id", $arr)){
            $reset['user_game_id']['value']=$arr['user_game_id'];
            $reset['user_game_id']['ZH']="使用者会员ID";
        }
        if(array_key_exists("user_nike_name", $arr)){
            $reset['user_nike_name']['value']=$arr['user_nike_name'];
            $reset['user_nike_name']['ZH']="使用者会员名";
        }
        if(array_key_exists("user_use_time", $arr) ){
            $reset['user_use_time']['value']=$arr['user_use_time'];
            // $reset['user_use_time']['value']=get_object_vars($arr['user_use_time'])['date'];
            $reset['user_use_time']['ZH']="使用时间";
        }
        if(array_key_exists("card_create_time", $arr)){

            $reset['card_create_time']['value']=$arr['card_create_time'];
            // $reset['card_create_time']['value']=get_object_vars($arr['card_create_time'])['date'];
            $reset['card_create_time']['ZH']="创建时间";
        }
        if(array_key_exists("spreaderaccount", $arr)){
            $reset['spreaderaccount']['value']=$arr['spreaderaccount'];
            $reset['spreaderaccount']['ZH']="推荐人账号";
        }
        if(array_key_exists("phonenum", $arr)){
            $reset['phonenum']['value']=$arr['phonenum'];
            $reset['phonenum']['ZH']="绑定手机";
        }
        if(array_key_exists("disablelogin", $arr)){
            $reset['disablelogin']['value']=$arr['disablelogin'];
            $reset['disablelogin']['ZH']="禁止登陆";
        }
        if(array_key_exists("crontolstatus", $arr)){
            $reset['crontolstatus']['value']=$arr['crontolstatus'];
            $reset['crontolstatus']['ZH']="操作状态";
        }
        if(array_key_exists("card_group", $arr)){
            $reset['card_group']['value']=$arr['card_group'];
            $reset['card_group']['ZH']="创建批次";
        }
        if(array_key_exists("card_type", $arr)){
            $id=$arr['id'];
                if($arr['card_type']==(int)-2){
                    $reset['scard_type']['value']="<a onclick='onenodel_grounp($id)' title=\"解冻\" class=\"contact-type\" style=\"display:inline-block\"><i class=\"fa fa-lock loc\"></i></a>";   //被冻结
                }else{
                    $reset['scard_type']['value']="<a onclick='onedel_grounp($id)' title=\"冻结\" class=\"contact-type\" style=\"display:inline-block\"><i class=\"fa fa-unlock loc\"></i></a>";   //被冻结
                } 
            $reset['scard_type']['ZH']="操作";
        }

        return $reset;
    }



}